//package com.matt.repository.impl;
//
//import com.matt.foundation.DO.StaffAreaDO;
//import com.matt.foundation.DO.StaffRoleDO;
//import com.matt.foundation.DO.TeacherDO;
//import com.matt.foundation.constant.StaffConstant;
//import com.matt.foundation.query.StaffQuery;
//import com.matt.repository.base.BaseNativeSqlRepository;
//import com.matt.repository.base.StaffRoleRepository;
//import org.apache.commons.lang.StringUtils;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//import java.util.Objects;
//
///**
// * *******************************
// * Created by Ron.
// * form com.matt
// * on 2017/8/29
// * *******************************
// */
//@Service
//public class StaffRoleRepositoryImpl extends BaseNativeSqlRepository implements StaffRoleRepository{
//
//    @Override
//    public List<StaffRoleDO> findStaffRolesById(String staffId) {
//        String findSql = String.format("SELECT s.id as staffId, s.realName as realName, r.roleCode as roleCode, r.roleName as roleName" +
//                " from staff s LEFT JOIN  rel_staff_role sr ON s.id =sr.staffId LEFT JOIN teach_role r ON sr.roleId = r.id " +
//                " where s.id = '%s' ", staffId);
//        List<StaffRoleDO> objectArrayList = sqlObjectList(findSql, StaffRoleDO.class);
//        return objectArrayList;
//    }
//
//
//    @Override
//    public List<StaffRoleDO> findStaffRoles() {
//        String findSql = String.format("SELECT s.id as staffId, s.realName as realName, r.roleCode as roleCode, r.roleName as roleName" +
//                " from staff s LEFT JOIN  rel_staff_role sr ON s.id =sr.staffId LEFT JOIN teach_role r ON sr.roleId = r.id " +
//                " where s.deleted = false");
//        List<StaffRoleDO> objectArrayList = sqlObjectList(findSql, StaffRoleDO.class);
//        return objectArrayList;
//    }
//
//    @Override
//    public List<StaffRoleDO> findStaffRolesByArea(String areaId, String name) {
//        String findSql = String.format("SELECT s.id as staffId, s.realName as realName, r.roleCode as roleCode, r.roleName as roleName" +
//                " from staff s LEFT JOIN  rel_staff_role sr ON s.id =sr.staffId LEFT JOIN teach_role r ON sr.roleId = r.id " +
//                " LEFT JOIN  area a ON a.dingDing_code = s.dingDingDepartmentId  where true ");
//        if (StringUtils.isNotBlank(name)) {
//            findSql += String.format(" and s.realName like concat('%s', '%s', '%s') ", "%", name, "%");
//        }
//        if (StringUtils.isNotBlank(areaId)) {
//            findSql += String.format(" and a.id='%s' ", areaId);
//        }
//        List<StaffRoleDO> objectArrayList = sqlObjectList(findSql, StaffRoleDO.class);
//        return objectArrayList;
//    }
//
//    @Override
//    public List<StaffAreaDO> findStaffByRole(String roleCode) {
//        String findSql = String.format("SELECT s.id as staffId, s.realName as realName, r.roleCode as roleCode, a.id as areaId " +
//                " from staff s LEFT JOIN  rel_staff_role sr ON s.id =sr.staffId LEFT JOIN teach_role r ON sr.roleId = r.id " +
//                " LEFT JOIN  area a ON a.dingDing_code = s.dingDingDepartmentId  where true ");
//        if (StringUtils.isNotBlank(roleCode)) {
//            findSql += String.format(" and r.roleCode='%s' ", roleCode);
//        }
//        List<StaffAreaDO> objectArrayList = sqlObjectList(findSql, StaffAreaDO.class);
//        return objectArrayList;
//    }
//
//    @Override
//    public List<TeacherDO> findStaffByAreaAndRole(String areaId, String roleCode) {
//        String findSql = String.format("SELECT s.id as id, s.realName as name, s.headImgUrl as imgUrl" +
//                " from staff s LEFT JOIN  rel_staff_role sr ON s.id =sr.staffId LEFT JOIN teach_role r ON sr.roleId = r.id " +
//                " LEFT JOIN area a on s.dingDingDepartmentId =a.dingding_code " +
//                " where r.roleCode = '%s' and a.id ='%s' and s.deleted = false", roleCode, areaId);
//        List<TeacherDO> objectArrayList = sqlObjectList(findSql, TeacherDO.class);
//        return objectArrayList;
//    }
//
//
//
//    @Override
//    public List<TeacherDO> findStaffByAreaAndRoles(String areaId, String roleCode1, String roleCode2) {
//        String findSql = String.format("SELECT s.id as id, s.realName as name, s.headImgUrl as imgUrl" +
//                " from staff s LEFT JOIN  rel_staff_role sr ON s.id =sr.staffId LEFT JOIN teach_role r ON sr.roleId = r.id " +
//                " LEFT JOIN area a on s.dingDingDepartmentId =a.dingding_code " +
//                " where (r.roleCode = '%s' or r.roleCode ='%s') and a.id ='%s' and s.status = '%s' and s.deleted = false ", roleCode1, roleCode2 ,areaId, StaffConstant.Status.NORMAL.codeOf());
//        List<TeacherDO> objectArrayList = sqlObjectList(findSql, TeacherDO.class);
//        return objectArrayList;
//    }
//
//    @Override
//    public List<Object[]> findStaffByDepartment(StaffQuery query) {
//        String findSql = String.format("SELECT s.id, s.realName, r.roleName, s.lastLogin, s.mobile, s.status " +
//                " from staff s LEFT JOIN  rel_staff_role sr ON s.id =sr.staffId LEFT JOIN teach_role r ON sr.roleId = r.id " +
//                " where s.dingDingDepartmentId ='%s'", query.getDingDingDepartmentId());
//        if (StringUtils.isNotBlank(query.getName())) {
//            findSql += String.format(" and s.realName like concat('%s', '%s', '%s') ", "%", query.getName(), "%");
//        }
//        if (StringUtils.isNotBlank(query.getRoleCode())) {
//            findSql += String.format(" and r.roleCode='%s' ", query.getRoleCode());
//        }
//        if (Objects.nonNull(query.getStatus())) {
//            findSql += String.format(" and s.status='%s' ", query.getStatus());
//        }
//
//        findSql += " order by s.created desc " ;
//        findSql += String.format(" limit %s, %s ", query.getPageNum() * query.getPageSize() ,  query.getPageSize());
//        List<Object[]> objectArrayList = sqlArrayList(findSql);
//        return objectArrayList;
//    }
//
//    @Override
//    public Long countStaffByDepartment(StaffQuery query) {
//        String findSql = String.format("SELECT count(s.id) " +
//                " from staff s LEFT JOIN  rel_staff_role sr ON s.id =sr.staffId LEFT JOIN teach_role r ON sr.roleId = r.id " +
//                " where s.dingDingDepartmentId ='%s'", query.getDingDingDepartmentId());
//
//        if (StringUtils.isNotBlank(query.getName())) {
//            findSql += String.format(" and s.realName like concat('%s', '%s', '%s') ", "%", query.getName(), "%");
//        }
//        if (StringUtils.isNotBlank(query.getRoleCode())) {
//            findSql += String.format(" and r.roleCode='%s' ", query.getRoleCode());
//        }
//        if (Objects.nonNull(query.getStatus())) {
//            findSql += String.format(" and s.status='%s' ", query.getStatus());
//        }
//        List objectArrayList = sqlSingleList(findSql);
//        return Long.valueOf(objectArrayList.get(0).toString());
//    }
//}
